//下面这段复刻了“罐中奶牛”配方
let sawCuttingRecipes={};let cutted=[]

const addCut=(o,e,i)=>{
    if (!sawCuttingRecipes[e]) sawCuttingRecipes[e]={}
    sawCuttingRecipes[e][i] = o
}
const addCuttingRecipe = (output, entity, input) => {
    //typeof an array is object, not array
    if (typeof entity == 'object') {
        if (typeof input == 'object') {//both plural
            for (e of entity) {
                for (i of input) {
                    addCut(output, e, i)
                }
            }
        }else{//entity plural, input singular
            for (e of entity) {
                addCut(output, e, input)
            }
        }
    }else{
        if (typeof input == 'object') {//entity singular, input plural
            for (i of input) {
                addCut(output, entity, i)
            }
        }else{//both singular
            addCut(output, entity, input)
        }
    }
}
onEvent('entity.attack',e=> {
    let block=e.entity.block.down;let type=e.entity.type
    if (e.source.type === 'create.mechanical_saw' 
	 && sawCuttingRecipes[type] 
	 && sawCuttingRecipes[type][block.id]) {
        block.set(sawCuttingRecipes[type][block.id])
        cutted.push(e.entity.id)
		e.entity.setPosition(e.entity.x, -60, e.entity.z)
        e.entity.kill()
    }
})
onEvent('entity.drops',e=>{
    let index = cutted.indexOf(e.entity.id)
    if (index > -1) {
        cutted.splice(index, 1)
        e.cancel()
    }
})

//测试
//改成闪电
addCuttingRecipe('mekanism:tin_ore', 'minecraft:snow_golem', 'minecraft:melon')